package com.star.controller;

import com.star.entity.Hotproducts;
import com.star.result.Result;
import com.star.service.HotproductsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @Author star
 * @Date 2023/4/1 13:23
 * @PackageName:com.star.controller
 * @ClassName: HotProductsController
 * @Description: TODO
 * @Version 1.0
 */
@Api(tags = "首页车介绍")
@RestController
@RequestMapping("/hotProducts")
public class HotProductsController {

    @Autowired
    private HotproductsService service;

    /**
     * 查询所有车型
     * @return
     */
    @ApiOperation("查询所有")
    @GetMapping("/list")
    public Result list(){
        List<Hotproducts> list = service.list();
        return Result.ok(list);
    }

    //查询单个车型
    @ApiOperation("根据id查询")
    @GetMapping("/{id}")
    public Result getById(@PathVariable int id){
        Hotproducts hotproducts = service.getById(id);
        return Result.ok(hotproducts);
    }

    @ApiOperation("根据id删除")
    @GetMapping("/del/{id}")
    public Result delById(@PathVariable int id){
        boolean b = service.removeById(id);
        if(b){
            return Result.ok();
        }else{
            return Result.fail();
        }
    }
}
